home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 9438 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  2.4 KB

  1. Path: solon.com!not-for-mail
  2. From: johnb@pivotal-dm.ccmail.compuserve.com (John Bain)
  3. Newsgroups: comp.lang.c,comp.lang.c.moderated
  4. Subject: Re: Integral promotion problem
  5. Date: 11 Mar 1996 06:28:36 -0600
  6. Organization: Pivotal Technologies Ltd.
  7. Sender: clc@solutions.solon.com
  8. Approved: clc@solutions.solon.com
  9. Message-ID: <4i169k$ht@solutions.solon.com>
  10. References: <31404525.26295649@dub-news-svc-3.compuserve.com>
  11. NNTP-Posting-Host: solutions.solon.com
  12. X-Newsreader: Forte Agent .99d/32.182
  13.  
  14.  
  15. tanmoy@qcd.lanl.gov (Tanmoy Bhattacharya) wrote:
  16.  
  17. > In article <4hqedq$1mj@solutions.solon.com>
  18. > johnb@pivotal-dm.ccmail.compuserve.com (John Bain) writes:
  19. > JB: The hex values and the result of the first "if" are the "surprising"
  20. > JB: results I was expecting.  However, the result of the second "if" has me
  21. > JB: confused.
  22. > JB: 
  23. > JB: What am I missing?
  24. > JB: 
  25. >
  26. > Compiler error? 
  27.  
  28. I'm glad it's the compiler, not me!
  29.  
  30. >
  31. > JB: (In case it's relevent, the implementation defines the conversion of an
  32. > JB: unsigned integer to a signed integer, when the unsigned value cannot be
  33. > JB: represented in the signed integer, as being performed by truncation of
  34. > JB: the most significant bits if the signed integer is shorter, and then
  35. > JB: interpreting the remaining bits as a 2's complement integer.)
  36. > Why should that be relevant? What am I missing?
  37.  
  38. I didn't think it was relevant, it's just that the results I was seeing
  39. were making me doubt my understanding so I thought I'd include the
  40. information just in case.  The reference section of K&R2 (the best
  41. definition I have, as I do not have a copy of the standard) says, in its
  42. definition of '~' (A7.4.6):
  43.  
  44. "The integral promotions are performed.  If the operand is unsigned, the
  45. result is computed by subtracting the value from the largest value of
  46. the promoted type.  If the operand is signed, the result is computed by
  47. converting the promoted operand to the corresponding unsigned type,
  48. applying ~, and converting it back to the unsigned type."
  49.  
  50. I didn't believe that the implementation defined unsigned->signed
  51. conversions were happening, but I didn't believe the results I was
  52. seeing either!
  53.  
  54. Incidentally, I assume that when it says "if the operand is unsigned" it
  55. means _before_ promotion?
  56.  
  57. > Cheers
  58. > Tanmoy
  59.  
  60. Thanks,
  61.  
  62. John
  63. -----------------------------------------------------------------
  64. John Bain                  
  65. johnb@pivotal-dm.ccmail.compuserve.com 
  66. -----------------------------------------------------------------
  67.